//
//  NSString+URLEncode.m
//  Monkey
//
//  Created by Yan Lee on 12-6-13. modified by songliu
//  Copyright (c) 2012年 ihandysoft. All rights reserved.
//

#import "NSString+URLEncode.h"

@implementation NSString (URLEncode)

- (NSString*)encodeURLwithEncoding:(NSStringEncoding)encoding
{
    return (__bridge_transfer  NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)self, NULL, CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), CFStringConvertNSStringEncodingToEncoding(encoding));
}

- (NSString *)decodeURLwithEncoding:(NSStringEncoding)encoding
{
    NSString *newString = [[self stringByReplacingOccurrencesOfString:@"+" withString:@" "]
                                            stringByReplacingPercentEscapesUsingEncoding:encoding];
    if (newString) {
		return newString;
	}
	return @"";
}

@end
